from qtpy import QtCore
from qtpy import QtWidgets
from qtpy import QtGui


class LabelAttrDialog(QtWidgets.QDialog):
    def __init__(self, parent=None) -> None:
        super().__init__(parent)
        self.treeWidget = QtWidgets.QTreeWidget(self)
        self.treeWidget.setColumnCount(2)
        self.treeWidget.setHeaderLabels([self.tr("名称"), self.tr("值")])
        self.treeWidget.header().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)

    def resizeEvent(self, event) -> None:
        # treeWidget 随父窗口大小变化
        self.treeWidget.resize(self.rect().size())
        return super().resizeEvent(event)

    def addLabelTree(self, shapes):
        for shape in shapes:
            # 添加标签
            current_label = QtWidgets.QTreeWidgetItem(self.treeWidget)
            current_label.setText(0, shape.label)
            # 添加属性
            for attr in shape.attributes:
                attr_name = attr["attr_name"]
                attr_value = attr["attr_value"]
                attr_item = QtWidgets.QTreeWidgetItem(current_label)
                attr_item.setText(0, attr_name)
                attr_item.setText(1, attr_value)

    def clearShapes(self):

        self.treeWidget.clear()
        # 添加形状点
        # TODO
    # TODO 添加清除列表 切换图片需要清除

    # 添加选择高亮

    # 添加形状点定位高亮
    # 双击记录
    # 应该有一个ID


if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ex = LabelAttrDialog()
    ex.show()
    sys.exit(app.exec_())
